<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
    <style>
        .account {
            width: 400px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div class="account">
    <h1 style="text-align: center;">注册</h1>
    <form method="post">
        {% csrf_token %}
        {% for field in form %}
            {% if field.name == 'code' %}
                <div class="form-group">
                    <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                    <div class="clearfix">
                        <div class="col-md-6" style="padding-left: 0;">{{ field }}</div>
                        <div class="col-md-6"><input type="button" class="btn btn-default"  id='get' value="点击获取验证码"></div>
                    </div>

                </div>
            {% else %}
                <div class="form-group">
                    <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                    {{ field }}
                </div>
            {% endif %}
        {% endfor %}

        <button type="submit" class="btn btn-primary">注 册</button>
    </form>

</div>

<script>
    $('#get').click(function () {
        var a = 61;
        var test1 = setInterval(function () {
            $('#get').attr('disabled','ture')
            a-=1;
            $('#get').val(a);

           if(a==0){
            clearTimeout(test1);
            $('#get').removeAttr('disabled')
            $('#get').val('点击获取验证码')
        }
        },1000);

        $.ajax(
            {
                'url':'/sms/',
                'type':'get',
                'data':{
                    'tpl':'register',
                    'phone':$('#id_mobile_phone').val()
                },
                success:function (ret) {
                    if (ret!='成功'){
                        alert('验证码发送失败')
                        clearTimeout(test1);
                    }
                },
                error:function (ret) {
                    console.log(ret)

                }
            }
        )

    })
</script>
</body>
</html>